﻿using System.Collections.Generic;
using System.Linq;
using FarmerJoe.Helpers;
using Styx;
using Styx.Patchables;
using Styx.WoWInternals.WoWObjects;

namespace FarmerJoe.Lists
{
    public static class NPCs
    {
        private static HashSet<uint> _bosses = new HashSet<uint> {};
        public static HashSet<string> CurrentMapBosses { get; private set; }

        static NPCs()
        {
            PopulateBosses();
            foreach (var bossId in _dummies)
            {
                _bosses.Add(bossId);
            }
        }

        public static bool IsBoss(this WoWUnit unit)
        {
            PopulateBosses();
            return CurrentMapBosses.Contains(unit.Name) || BossIds.Contains(unit.Entry);
        }

        public static void PopulateBosses()
        {
            if (!Timers.AutoExpire("Boss IDs", 10000) && CurrentMapBosses.Count >= 0) return;
            CurrentMapBosses = new HashSet<string>();
            CurrentMapBosses = new HashSet<string>(StyxWoW.Db[ClientDb.DungeonEncounter].Where(r => r.GetField<int>(1) == StyxWoW.Me.MapId).Select(r => r.GetStringField(5)));
        }

        private static HashSet<uint> BossIds
        {
            get
            {   
                foreach (var bossId in _dummies)
                {
                    _bosses.Add(bossId);
                }

                return _bosses;
            }
        }

        public static HashSet<uint> IgnoreMobs = new HashSet<uint>
                                                     {
                                                         52288, // Venomous Effusion (NPC near the snake boss in ZG. Its the green lines on the ground. We want to ignore them.)
                                                         52302, // Venomous Effusion Stalker (Same as above. A dummy unit)
                                                         52320, // Pool of Acid
                                                         52525, // Bloodvenom

                                                         52387, // Cave in stalker - Kilnara
                                                     };

        public static HashSet<uint> TrainingDummies{get { return _dummies; }}

        //public static HashSet<uint> CanShredBoss { get { return _shred; } }

        private static readonly HashSet<uint> _dummies = new HashSet<uint>
                                                             {
                31146, // Raider's
                46647, // 81-85
                32546, // Ebon Knight's (DK)
                31144, // 79-80
                32543, // Veteran's (Eastern Plaguelands)
                32667, // 70
                32542, // 65 EPL
                32666, // 60
                30527, // ?? Boss one (no idea?)
            };

        private static readonly HashSet<uint> _shred = new HashSet<uint>
                                                           {
                56846, // Arm Tentacle -- Madness of DW
                56167, // Arm Tentacle -- Madness of DW
                56168, // Wing Tentacle - Madness of DW
                57962, // Deathwing ----- Madness of DW (his head)
                56471, // Mutated Corruption 
            };


    }
}
